<?php
header("Content-Type: text/html; charset=utf8");
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$conn->set_charset("utf8");
// 接收前端传递的数据

$data = file_get_contents("php://input");
$registerinfo = json_decode($data, true);
$id = $registerinfo['id'] ?? '';
$name = $registerinfo['name'] ?? '';
$college = $registerinfo['college'] ?? '';
$grade = $registerinfo['grade'] ?? '';

// 插入数据到数据库
$sql = "INSERT INTO user (id, name, college, grade) VALUES ('$id', '$name', '$college', '$grade')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

// 关闭数据库连接
$conn->close();
?>
